<template>
	<view>
		<view class="components-new">
			<u-alert-tips style="margin: 30rpx;" type="error" v-if="userCredit.creditNum < 1" title="学分不足提醒！！！" :description="'您当前的学分: ' + userCredit.creditNum"></u-alert-tips>
			<u-card v-for="(item, index) in dataList" :key="index" :title="item.title" title-color="#18b566" :sub-title="item.createDate">
				<view class="" slot="body">
					<view class="u-body-item u-flex u-border-bottom u-col-between u-p-t-0">
						<view class="u-body-item-title">{{item.content}}</view>
						<image
							:src="item.imgUrl"
							mode="aspectFill"></image>
					</view>
					<view style="margin-top: 20rpx;">
						<u-button type="success" size="mini" @tap="activitySignUp(item.id)">点击报名</u-button>
					</view>
				</view>
			</u-card>
		</view>
		<tabbar-footer></tabbar-footer>
	</view>
</template>

<script>
	import {
		getAllNews,
		signup,
		getCredit
	} from '@/api/new/news.js'
	import tabbarFooter from '../tabbar/tabbar-footer.vue'
	export default {
		data() {
			return {
				dataList: [],
				signupData: {},
				userId: '',
				userCredit: {},
				intervalId: null
			}
		},
		components: {
			tabbarFooter
		},
		onLoad() {
			this.getAllNewList()
			this.userId = uni.getStorageSync('userId')
			this.getCredit()
		},
		methods: {
			getAllNewList() {
				getAllNews().then(res => {
					this.dataList = res.data
				})
			},
			activitySignUp(id) {
				this.signupData.activityeId = id
				signup(this.signupData).then(res => {
					if (res.code == 0) {
						uni.showToast({
							title: '报名成功！',
							icon: 'success'
						});
					} else {
						uni.showToast({
							title: res.data.msg,
							icon: 'error'
						});
					}
				})
			},
			getCredit() {
				getCredit(this.userId).then(res => {
					console.log(res.data)
					this.userCredit = res.data
				})
			}
			
		}
	}
</script>

<style scoped lang="scss">
	.u-card-wrap {
		background-color: $u-bg-color;
		padding: 1px;
	}

	.u-body-item {
		font-size: 32rpx;
		color: #333;
		padding: 20rpx 10rpx;
	}

	.u-body-item image {
		width: 120rpx;
		flex: 0 0 120rpx;
		height: 120rpx;
		border-radius: 8rpx;
		margin-left: 12rpx;
	}
</style>